<?php

include_once __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/../db.php';

// var_dump(\Data::query()->delete());
// exit;

$start = null; // strtotime('2020-06-22 22:00:00');

$nextDraw1 = getNextDraw(1, $start);
$data1 = \Data::where('type', 1)
    ->where('date', '>=', date('Y-m-d', mktime(0, 0, 0, 1, 1, date("Y"))))
    ->where('date', '<', substr($nextDraw1, 0, 10))
    ->orderBy('date', 'asc')
    ->get();

$current1 = $data1->last();

$nextDraw2 = getNextDraw(2, $start);
$data2 = \Data::where('type', 2)
    ->where('date', '>=', date('Y-m-d', mktime(0, 0, 0, 1, 1, date("Y"))))
    ->where('date', '<', substr($nextDraw2, 0, 10))
    ->orderBy('date', 'asc')
    ->get();

$current2 = $data2->last();

$nextDraw3 = getNextDraw(3, $start);
$data3 = \Data::where('type', 3)
    ->where('date', '>=', date('Y-m-d', mktime(0, 0, 0, 1, 1, date("Y"))))
    ->where('date', '<', substr($nextDraw3, 0, 10))
    ->orderBy('date', 'asc')
    ->get();

$current3 = $data3->last();

$draws = [
    [
        'type' => 1,
        'pic' => '//wojianishanghaojiugoujia.gitee.io/public-pages/imgs/ball1.png',
        'bg' => 'card-bg-purple',
        'current' => $current1,
        'trending' => $data1,
        'nextDraw' => $nextDraw1,
        'i' => 48,
    ],
    [
        'type' => 2,
        'pic' => '//wojianishanghaojiugoujia.gitee.io/public-pages/imgs/ball2.png',
        'bg' => 'card-bg-orange',
        'current' => $current2,
        'trending' => $data2,
        'nextDraw' => $nextDraw2,
        'i' => 4,
    ],
    [
        'type' => 3,
        'pic' => '//wojianishanghaojiugoujia.gitee.io/public-pages/imgs/ball3.png',
        'bg' => 'card-bg-green',
        'current' => $current3,
        'trending' => $data3,
        'nextDraw' => $nextDraw3,
        'i' => 36,
    ],
];

include __DIR__ . '/../page.phtml';
